<template>
  <div ref="chartdiv" class="grid-content" />
</template>

<script>
require('echarts/theme/macarons') // echarts theme
import resize from '@/mixins/resize'
import { toPercent, toSizeStr } from '@/utils/index.js'

const animationDuration = 600

export default {
  filters: {
  },
  mixins: [resize],
  props: {
    dir: {
      type: String,
      require: true,
      default: ''
    },
    sysType: {
      type: String,
      default: ''
    },
    usage: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
    usage: function(newVal, oldVal) {
      if (newVal && this.chart) {
        this.chart.setOption({
          title: {
            text: '挂载点: ' + this.dir + '\n\n类型: ' + this.sysType + '\n\n总大小:' + toSizeStr(this.usage.total * 1000),
            x: 'center',
            y: 'bottom',
            textStyle: {
              fontSize: 12,
              fontStyle: 'normal',
              fontWeight: 'normal'
            }
          },
          series: [{
            name: '使用量',
            type: 'gauge',
            detail: {
              formatter: function(param) {
                return toPercent(param / 100)
              },
              fontSize: 13
            },
            data: [{
              value: this.usage.used / this.usage.total * 100,
              name: '使用量'
            }],
            animationDuration
          }]
        })
      }
      this.chart.resize()
    }
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  mounted() {
    this.initChart()
  },
  methods: {
    initChart() {
      this.chart = this.$echarts.init(this.$refs.chartdiv, 'macarons')
    }
  }
}
</script>

<style lang="scss" >
.box-card-component {
  .el-card__header {
    padding: 0px !important;
  }
  .el-card__body {
    padding: 0px !important;
  }
}
</style>
<style lang="scss" scoped>
.box-card-component {
  .box-card-header {
    position: relative;
    height: 220px;
    img {
      width: 100%;
      height: 100%;
      transition: all 0.2s linear;
      &:hover {
        transform: scale(1.1, 1.1);
        filter: contrast(130%);
      }
    }
  }
  .card-panel-text {
    line-height: 18px;
    color: rgba(0, 0, 0, 0.55);
    font-size: medium;
    font-weight: bold;
    margin-top: 14px;
    margin-left: 14px;
  }
  .progress-item {
    margin-bottom: 10px;
    font-size: 14px;
  }
  .el-header,
  .el-footer {
    background-color: #a4a4e6;
    color: #333;
    text-align: center;
    line-height: 60px;
  }

  .el-aside {
    background-color: #d3dce6;
    color: #333;
    div {
      text-align: center;
      vertical-align: middle;
      display: table-cell;
      margin: auto;
    }
  }

  .el-main {
    // background-color: #e9eef3;
    color: #333;
    text-align: center;
    vertical-align: middle;
    line-height: 40px;
  }

  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
  .el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: #99a9bf;
  }
  .bg-purple {
    background: #d3dce6;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
    text-align: center;
    vertical-align: middle;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
  @media only screen and (max-width: 1510px) {
    .mallki-text {
      display: none;
    }
  }
}
</style>
